package org.logstashplugins.Cache;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 缓存管理器
 */
public class CacheManager {

    private static ConcurrentHashMap<String,RegexCache> caches;

    static {
        caches = new ConcurrentHashMap<>();
    }

    public static boolean putCache(RegexCache regexCache){
        if(caches.containsKey(regexCache.getCacheId())){
            return false;
        }
        caches.put(regexCache.getCacheId(), regexCache);
        return true;
    }

    public static RegexCache getCache(String cacheId){
        return caches.get(cacheId);
    }

    public static Set<RegexCache> getCaches(List<String> cacheIds){
        Set<RegexCache> cacheSet = new HashSet<>();
        for(String cacheId : cacheIds){
            cacheSet.add(caches.get(cacheId));
        }
        return cacheSet;
    }
}
